
type __native_platform__ = 'ios'|'android'|'virtual';
const NATIVE_PLATFORM: __native_platform__ = 'android';

export default class Ab_NativeClient_bA {
	private static Ab_client_bA: Ab_NativeClientIns_bA;

	public static Ab_initClient_bA(init_call: (platform: __native_platform__)=>Ab_NativeClientIns_bA){
		let client = init_call(NATIVE_PLATFORM);
		if(client){
			abi.Ab_log_bA.Ab_enable_debug_mode_bA(NATIVE_PLATFORM=='virtual');
			Ab_NativeClient_bA.Ab_client_bA = client;
		}
	}

	public static Ab_sendMessage_bA<A extends Ab_NCAPIStructure_bA<any, any>>(api: string, data?: any, ccdata?: any): A{
		data = data ?? {}
		abi.Ab_log_bA.Ab_tag_bA([
			['NATIVE', 'tan'],
			['SEND', 'skyblue']
		].map(el=>el[0]+':'+el[1]).join(';'), api, '\n~~~~~~~~~~\nDATA:', data, '\n~~~~~~~~~~\n');

		let struct: A;
		if(this.Ab_client_bA){
			struct = this.Ab_client_bA.Ab_callStaticMethod_bA(api, data, ccdata);
		}else{
			abi.Ab_log_bA.Ab_tag_bA('没有原生端服务: tomato');
		}

		struct.Ab_response_bA.then(res=>{
			abi.Ab_log_bA.Ab_tag_bA([
				['NATIVE', 'tan'],
				['BACK', 'lime']
			].map(el=>el[0]+':'+el[1]).join(';'), api, '\n~~~~~~~~~~\nSTRUCT:', struct, '\nRESULT:', res, '\n~~~~~~~~~~\n');
		});

		return struct;
	}
}

export abstract class Ab_NativeClientIns_bA {
	public abstract Ab_callStaticMethod_bA(api: string, data: any, ccdata?: any): any;
}

/** 请求结构 */
export interface Ab_NCAPIStructure_bA<Ab_Req_bA, Ab_Res_bA> {
	/** 请求接口标识符 */
	Ab_api_bA: string;
	/** 请求数据 */
	Ab_request_bA: Ab_Req_bA;
	/** 响应数据 */
	Ab_response_bA: Promise<Ab_Res_bA>;
}
